package com.foreknow.springboot_demo.mapper;

import com.foreknow.springboot_demo.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface DeliveryAddressMapper {
    /**
     * 根据用户编号查询所属送货地址
     * @param userId
     * @return
     */
    @Select("select * from deliveryAddress where userId=#{userId}")
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId);

    /**
     * 根据送货地址编号查询送货地址
     * @param daId
     * @return
     */
    @Select("select * from deliveryAddress where daId=#{daId}")
    public DeliveryAddress getDeliveryAddressById(int daId);

    /**
     * 向送货地址表中添加一条记录
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @param userId
     * @return
     */
    @Insert("insert into deliveryaddress(contactName,contactSex,contactTel,address,userId) values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public Integer saveDeliveryAddress(@Param("contactName")String contactName,@Param("contactSex")int contactSex,@Param("contactTel")String contactTel,@Param("address")String address,@Param("userId")String userId);

    /**
     * 根据送货地址编号更新送货地址信息
     * @param contactName
     * @param contactSex
     * @param contactTel
     * @param address
     * @return
     */
    @Update("update deliveryaddress set contactName = #{contactName},contactSex = #{contactSex},contactTel = #{contactTel},address = #{address} where daId = #{daId}")
    public Integer updateDeliveryAddress(@Param("daId")int daId,@Param("contactName")String contactName,@Param("contactSex")int contactSex,@Param("contactTel")String contactTel,@Param("address") String address);

    /**
     * 根据送货地址编号删除一条记录
     * @param daId
     * @return
     */
    @Delete("delete from deliveryaddress where daId = #{daId}")
    public Integer removeDeliveryAddress(int daId);
}
